#include "ConsoleApplication.h"

#include <QCoreApplication>
#include <QTimer>

//#include <base/BaseLog.h>
//#include <file/StandardIO.h>

ConsoleExecutable::ConsoleExecutable(int ArgC, char *ArgV[],
                                     QObject * child)
    : SerialExecutable(0, this)
    , _coreApp_p(new QCoreApplication(ArgC, ArgV))
{
    //BFUNCTION(ArgC, qptrdiff(ArgV), qptrdiff(child));
    if (child) child->setParent(this);
    /*BCONNECT(something, SIGNAL(aboutToSomething()),
             this, SLOT(deleteLater())); */
    //BCONNECT(this, SIGNAL(initialized()), this, SLOT(setup()));
    //BCONNECT(this, SIGNAL(setuped()), this, SLOT(start()));
    connect(this, SIGNAL(initialized()), this, SLOT(setup()));
    connect(this, SIGNAL(setuped()), this, SLOT(start()));
    QTimer::singleShot(10, this, SLOT(initialize()));
}

ConsoleExecutable::~ConsoleExecutable()
{
    // kill children
    // and clean up the mess
}

QCoreApplication * ConsoleExecutable::app(void) const
{   return _coreApp_p; }

void ConsoleExecutable::initialize(void)
{
    //BFUNCTION();
    SerialExecutable::initialize();
    // do stuff
    doInitialize();
    emit (initialized());
}

void ConsoleExecutable::setup(void)
{
    //BFUNCTION();
    SerialExecutable::setup();
    // do stuff
    doSetup();
    emit (setuped());
}

void ConsoleExecutable::start(void)
{
    //BFUNCTION();
    SerialExecutable::start();
    // do stuff
    doStart();
    emit (started());
}
